(function (angular) {
    'use strict';

    var module = angular.module('sinbad.promote.main', ['ngResource', 'highcharts-ng', 'ui.bootstrap.modal']);

    module.controller("ProheaderChartCtrl", ["$scope", function ($scope) {
        $scope.price_my = 2000;
        $scope.stock_sum = 953;
        $scope.sales_sum = 47;
        $scope.price_max = 0.5;
        $scope.Bid_rate = 108;
        $scope.prices_max = 0.54;

    }]);

    module.controller('ProbodyChartCtrl', ['$scope', '$uibModal', function ($scope, $modal) {
        $scope.promote = {
            autoType: 2
        };

    }]);
    module.controller('ProtabCharCrtl', ['$scope', '$uibModal', '$state', function ($scope, $modal, $state) {
        $scope.promote = {
            autoType: 2
        };

        $scope.currentTab = 'creative';


        $scope.switchTab = function (state) {
            //$scope.currentTab = 'keyword';
            $state.go(state);
        };
        $scope.switchTab1 = function (state) {
            //$scope.currentTab = 'creative';
            $state.go(state);
        };
        $scope.switchTab2 = function (state) {
            //$scope.currentTab = 'crowd';
            $state.go(state);
        };


        $scope.$on('tab.switch', function (event, data) {
            $scope.currentTab = data.name;
        })

    }]);

    module.controller('ProkeyChartCtrl', ['$scope', '$uibModal', function ($scope, $modal) {
        $scope.$emit('tab.switch', {name: 'keyword'});
        $scope.promote = {
            autoType: 2
        };
        $scope.pros = [{
            gjc: "网店设计",
            zt: "推广中",
            cj: 2.1,
            pp: "广泛匹配",
            zl: 8,
            djl: 8,
            zxl: 342,
            CPC: 45,
            cje: 5435,
            CVR: 0.8,
            ROI: 0.32,
            yd: "查排名",
            pm: "查排名"
        }];

        $scope.addkeyword = function () {
            var modaInstance = $modal.open({
                templateUrl: 'views/promote/promote_addword.html',
                controller: 'ProaddkeyCtrl',
                size: 500,
                backdrop: 'static',
                resolve: {
                    addword: function () {
                        return $scope.addword;

                    }
                }
            });

            modaInstance.result.then(function (addword) {
                    console.log('addword', addword);
                },
                function () {

                });
        };

        $scope.delkeyword = function () {
            var modaInstance = $modal.open({
                templateUrl: 'views/promote/promote_delword.html',
                controller: 'ProdelkeyCtrl',
                size: 500,
                backdrop: 'static',
                resolve: {
                    delword: function () {
                        return $scope.delword;

                    }
                }
            });

            modaInstance.result.then(function (delword) {
                    console.log(' delword', delword);
                },
                function () {

                });
        };
        $scope.moredata = function () {
            var modaInstance = $modal.open({
                templateUrl: 'views/promote/promote_moreword.html',
                controller: 'PromoredataCtrl',
                size: 500,
                backdrop: 'static',
                resolve: {
                    promoredata: function () {
                        return $scope.promoredata;

                    }
                }
            });

            modaInstance.result.then(function (promoredata) {
                    console.log('promoredata', promoredata);
                },
                function () {

                });
        };


    }]);

    module.controller('ProcreChartCtrl', ['$scope', '$uibModal', function ($scope, $modal) {
        $scope.$emit('tab.switch', {name: 'creative'});
        $scope.promotes = [{
            id: 2000,
            sta: "投放中",
            cre: 'http://placehold.it/100x100',
            pla: "PC",
            sho: 4353,
            clc: 543,
            clk: 0.2,
            cos1: 432,
            js: "正宗川味麻辣烫香肠腊肉喷香特制",
            jia: 40
        },
            {
                id: 2000,
                sta: "投放中",
                cre: 'http://placehold.it/100x100',
                pla: "PC",
                sho: 4353,
                clc: 543,
                clk: 0.2,
                cos1: 432,
                js: "正宗川味麻辣烫香肠腊肉喷香特制",
                jia: 40
            }
        ];


        $scope.promote = {};

        $scope.addCreative = function () {
            $scope.showCreativeEditor = true;
            $scope.showCreativeEditor1 = false;
        };

        $scope.addCreative1 = function () {
            $scope.showCreativeEditor = true;
            $scope.showCreativeEditor1 = true;
        };

        $scope.openAddCreative = function () {
            var modaInstance = $modal.open({
                templateUrl: 'views/promote/addCreative.html',
                controller: 'ProaddCreCtrl',
                size: 500,
                backdrop: 'static',
                resolve: {
                    promotecre: function () {
                        return $scope.promotecre;
                    }
                }
            });

            modaInstance.result.then(function (promotecre) {
                    console.log('promotecre', promotecre);
                },
                function () {

                });
        };

        $scope.imgOptimize = function () {
            var modaInstance = $modal.open({
                templateUrl: 'views/promote/img_optimization.html',
                controller: 'ProImgCreCtrl',
                backdrop: 'static',
                size: 'lg',
                resolve: {
                    promoteimg: function () {
                        return $scope.promoteimg;
                    }
                }
            });

            modaInstance.result.then(function (promoteimg) {
                    console.log('promoteimg', promoteimg);
                },
                function () {

                });
        };
    }]);
    module.controller('ProcrowdChartCtrl', ['$scope', '$uibModal', function ($scope, $modal) {
        $scope.$emit('tab.switch', {name: 'crowd'});

    }]);

    module.controller('ProaddCreCtrl', ['$scope', '$uibModalInstance', 'promotecre',
        function ($scope, $uibModalInstance, promotecre) {
            $scope.promotecre = promotecre;
            $scope.ok = function () {
                $uibModalInstance.close($scope.promotecre);
            };
            $scope.cancel = function () {
                $uibModalInstance.dismiss('cancel')

            };
        }]);
    module.controller('ProImgCreCtrl', ['$scope', '$uibModalInstance', 'promoteimg',


        function ($scope, $uibModalInstance, promoteimg) {
            $scope.promoteimg = promoteimg;
            $scope.ok = function () {
                $uibModalInstance.close($scope.promoteimg);
            };
            $scope.cancel = function () {
                $uibModalInstance.dismiss('cancel')

            };
            $scope.currentTab = 'hanxi';

            $scope.showhanxi = function () {
                $scope.currentTab = 'hanxi';
                $scope.hanxiimg = false;
                $scope.daqiimg = false;
                $scope.dongganimg = false;
                $scope.fuguimg = false;
                $scope.xuankuimg = false;
                $scope.qingxinimg = false;
                $scope.youyaimg = false;
                $scope.yundongimg = false;

            };
            $scope.showdaqi = function () {
                $scope.currentTab = 'daqi';
                $scope.hanxiimg = true;
                $scope.daqiimg = true;
                $scope.dongganimg = false;
                $scope.fuguimg = false;
                $scope.xuankuimg = false;
                $scope.qingxinimg = false;
                $scope.youyaimg = false;
                $scope.yundongimg = false;

            };
            $scope.showdonggan = function () {
                $scope.currentTab = 'donggan';
                $scope.hanxiimg = true;
                $scope.daqiimg = false;
                $scope.dongganimg = true;
                $scope.fuguimg = false;
                $scope.xuankuimg = false;
                $scope.qingxinimg = false;
                $scope.youyaimg = false;
                $scope.yundongimg = false;

            };
            $scope.showfugu = function () {
                $scope.currentTab = 'fugu';
                $scope.hanxiimg =  true;
                $scope.daqiimg = false;
                $scope.dongganimg = false;
                $scope.fuguimg = true;
                $scope.xuankuimg = false;
                $scope.qingxinimg = false;
                $scope.youyaimg = false;
                $scope.yundongimg = false;

            };
            $scope.showxuanku = function () {
                $scope.currentTab = 'xuanku';
                $scope.hanxiimg = true;
                $scope.daqiimg = false;
                $scope.dongganimg = false;
                $scope.fuguimg = false;
                $scope.xuankuimg = true;
                $scope.qingxinimg = false;
                $scope.youyaimg = false;
                $scope.yundongimg = false;

            };
            $scope.showqingxin = function () {
                $scope.currentTab = 'qingxin';
                $scope.hanxiimg = true;
                $scope.daqiimg = false;
                $scope.dongganimg = false;
                $scope.fuguimg = false;
                $scope.xuankuimg = false;
                $scope.qingxinimg = true;
                $scope.youyaimg = false;
                $scope.yundongimg = false;

            };
            $scope.showyouya = function () {
                $scope.currentTab = 'youya';
                $scope.hanxiimg = true;
                $scope.daqiimg = false;
                $scope.dongganimg = false;
                $scope.fuguimg = false;
                $scope.xuankuimg = false;
                $scope.qingxinimg = false;
                $scope.youyaimg = true;
                $scope.yundongimg = false;

            };
            $scope.showyundong = function () {
                $scope.currentTab = 'yundong';
                $scope.hanxiimg = true;
                $scope.daqiimg = false;
                $scope.dongganimg = false;
                $scope.fuguimg = false;
                $scope.xuankuimg = false;
                $scope.qingxinimg = false;
                $scope.youyaimg = false;
                $scope.yundongimg = true;

            };

        }]);
    module.controller('ProaddkeyCtrl', ['$scope', '$uibModalInstance', 'addword',
        function ($scope, $uibModalInstance, addword) {
            $scope.addword = addword;
            $scope.ok = function () {
                $uibModalInstance.close($scope.addword);
            };
            $scope.cancel = function () {
                $uibModalInstance.dismiss('cancel')

            };


        }]);
    module.controller('ProdelkeyCtrl', ['$scope', '$uibModalInstance', 'delword',
        function ($scope, $uibModalInstance, delword) {
            $scope.delword = delword;
            $scope.ok = function () {
                $uibModalInstance.close($scope.delword);
            };
            $scope.cancel = function () {
                $uibModalInstance.dismiss('cancel')

            };


        }]);


    module.controller('PromoredataCtrl', ['$scope', '$uibModalInstance', 'promoredata',
        function ($scope, $uibModalInstance, promoredata) {

            $scope.songdan = function (name) {
                if($scope.promoredatas && $scope.promoredatas.length > 8) {
                    alert("最多设置9项!");
                    $scope[name] = false;
                    console.log('promoredata', promoredata);
                    return;
                }
                var promoredata = new  Array();
                if ($scope.zxl == true) promoredata.push('zxl');
                if ($scope.zhf == true) promoredata.push('zhf');
                if ($scope.cpc == true) promoredata.push('cpc');
                if ($scope.zjcje == true) promoredata.push('zjcje');
                if ($scope.jjcje == true) promoredata.push('jjcje');
                if ($scope.zscs == true) promoredata.push('zscs');
                if ($scope.scdps == true) promoredata.push('scdps');
                if ($scope.zcje == true) promoredata.push('zcje');
                if ($scope.djzhl == true) promoredata.push('djzhl');
                if ($scope.jjgwcs == true) promoredata.push('jjgwcs');
                if ($scope.pjzxpm == true) promoredata.push('pjzxpm');
                if ($scope.djl == true) promoredata.push('djl');
                if ($scope.djv == true) promoredata.push('djv');
                if ($scope.qczxhf == true) promoredata.push('qczxhf');
                if ($scope.zjcjbs == true) promoredata.push('zjcjbs');
                if ($scope.jjcjbs == true) promoredata.push('jjcjbs');
                if ($scope.scbbs == true) promoredata.push('scbbs');
                if ($scope.roi == true) promoredata.push('roi');
                if ($scope.zcjbs == true) promoredata.push('zcjbs');
                if ($scope.zjgwcs == true) promoredata.push('zjgwcs');
                if ($scope.zgwcs == true) promoredata.push('zgwcs');
                if ($scope.tjsj == true) promoredata.push('tjsj');

                $scope.promoredatas=promoredata;

                console.log('promoredata', promoredata);

            };

            $scope.ok = function () {
                $uibModalInstance.close($scope.promoredatas);
            };
            $scope.cancel = function () {
                $uibModalInstance.dismiss('cancel')

            };


        }]);

})(angular);


